package com.lee.rpc.protocal.spring.reference;

import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
 
import com.lee.rpc.protocal.spring.reference.SpringRpcReferencePostProcessor;

@Configuration
public class RpcReferenceAutoConfiguration implements EnvironmentAware{

	private Environment environment;
	
	@Override
	public void setEnvironment(Environment environment) {
		// TODO Auto-generated method stub
		this.environment = environment;
	}
	
	@Bean
	public SpringRpcReferencePostProcessor postProcessor() {
		RpcClientProperties rpcClientProperties = new RpcClientProperties();
		rpcClientProperties.setServiceAddress(this.environment.getProperty("netty.client.serviceAddress"));
		rpcClientProperties.setServicePort(Integer.parseInt(this.environment.getProperty("netty.client.servicePort"))); 
		return new SpringRpcReferencePostProcessor(rpcClientProperties);
	}

	
}
